package com.woniuxy.sms.controller;

import com.woniuxy.common.result.Result;
import com.woniuxy.sms.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信服务
 */
@RestController
@RequestMapping("/sms")
public class SmsController {

    // spring中 可以通过过IOC + 和 构造器进行初始化 对象
//    private final SmsService smsService;
//    public SmsController(SmsService smsService) {
//        this.smsService = smsService;
//    }

    @Autowired
    private SmsService smsService;

    /**
     * 获取验证码
     * springmvc 流程     3
     * @Bean 的生命周期   2   不会
     * 循环依赖           1
     *
     */
    @GetMapping("/{phone}")
    public Result sendCode(@PathVariable("phone")String phone) {
        String code = smsService.sendCode(phone);
        return Result.ok(code);
    }

}